package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Destination;
import cn.wolfcode.luowowo.article.domain.MonthCommend;
import cn.wolfcode.luowowo.article.mapper.MonthCommendMapper;
import cn.wolfcode.luowowo.article.service.IDestinationService;
import cn.wolfcode.luowowo.article.service.IMonthCommendService;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@Service
public class MonthCommendServiceImpl implements IMonthCommendService {
    @Autowired
    private MonthCommendMapper monthCommendMapper;
    @Reference
    private IDestinationService destinationService;
    public MonthCommend selectListForMonth(long month) {
        MonthCommend ms = monthCommendMapper.selectListForMonth(month);
        List<Destination> list = new ArrayList<>();
        for(Long id:ms.getDestIds()){
            Destination destination = destinationService.getById(id);
            list.add(destination);
        }
        if(list.size()>6){
            list = list.subList(0,6);
        }
        ms.setDests(list);
        return ms;
    }
}
